<HTML>
<HEAD>
<TITLE>JavaScript Source Code 3000:  Games:  Rocket Blaster</TITLE>
<META HTTP-EQUIV="JavaScript Source Code 3000" CONTENT = "no-cache">
<META NAME="date" CONTENT="2000-09-09">
<META NAME="channel" CONTENT="Web Developer">
<META NAME="author" CONTENT="Brian Gosselin (bgaudiodr@aol.com)">
<META NAME="section" CONTENT="Games">
<META NAME="description" CONTENT="Use your mouse to aim and shoot at rockets that fly across the screen.  It may require some practice timing the shots to compensate for the distances.  Interestingly, the game never ends -- just play as long as you want.  Sweet!">
</HEAD>

<BODY BGCOLOR=#ffffff vlink=#0000ff>

<BR>
<center>
<table width=600 cellpadding=0 cellspacing=10>
<tr>
<td width=468 align=center>

    
    
</td>
<td width=120 align=center>
    
</td>
</tr>
</table>
<BR>
<BR>
<basefont size=3>
<FONT SIZE="+2" FACE="Helvetica,Arial">
<A HREF="../index.htm" /" TARGET="_top"><FONT COLOR="#0000FF"><b>Home</b></font></A>
<img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}">
<A HREF="index.htm" /games/"><font color="#FF0000"><b>Games</b></font></A>
<img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}">
<FONT COLOR="#006666"><b>Rocket Blaster</b></font></font>
<BR>
<BR>
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td><font FACE="helvetica,arial,geneva">
<br>
<br>
<!-- Description --><!--content_start-->
Use your mouse to aim and shoot at rockets that fly across the screen.  It may require some practice timing the shots to compensate for the distances.  Interestingly, the game never ends -- just play as long as you want.  Sweet!
<hr>
</td></tr>
</table>
<!-- Demonstration -->
<center>
<form name="open-rockets">
<input type=button value="Play Rocket Blaster" onClick="window.open('rocket-blaster-demo.html','rocketblaster','top=100,left=100,width=550,height=350');">
</form>
<a href="../img/rocket-blaster/rocket-blaster.zip" /img/rocket-blaster/rocket-blaster.zip">Images Needed (Zip File)</a>
</center>
<P>
<P>
<a name="source">
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td BGCOLOR=yellow><font FACE="helvetica,arial,geneva"><b>JavaScript Source Code 3000:  Games:  Rocket Blaster</b>
<p>Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s).  The script is yours!!!
<br><br></font></td></tr>
<tr><td BGCOLOR=yellow ALIGN=CENTER>
<form NAME="copy">

<DIV align="center">
<input type=button value="Highlight All" onClick="javascript:this.form.txt.focus();this.form.txt.select();">&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="total" VALUE="Script Size:  9.26 KB" size=24>
</DIV>

<textarea NAME="txt" ROWS=20 COLS=75 WRAP=VIRTUAL>

&lt;!-- THREE STEPS TO INSTALL ROCKET BLASTER:

  1.  Save the entire first HTML page as rocket-blaster.html
  2.  Paste the second code into your page to open the game
  3.  Download the game images and upload them to your server  --&gt;

&lt;!-- STEP ONE: Save the entire first HTML page as rocket-blaster.html  --&gt;

&lt;html&gt;
&lt;head&gt;
&lt;style type = "text/css"&gt;
.basic {position:absolute; visibility:visible; top:-3000px;}
&lt;/style&gt;

&lt;SCRIPT LANGUAGE="JavaScript"&gt;
&lt;!-- Original:  Brian Gosselin (bgaudiodr@aol.com) --&gt;
&lt;!-- Web Site:  http://www.bgaudiodr.iwarp.com --&gt;

&lt;! &gt;
&lt;! &gt;

&lt;!-- Begin
var yoffset = 20; // pixels from top

var isNS = (document.layers);
var _all =  (isNS) ? 'outer.document.' : 'all.' ;
var _style =  (isNS) ? '' : '.style' ;
var _visible =  (isNS) ? 'show' : 'visible' ;
var py = 0, px = 0, xoffset, loaded = false, obj = new Object();
var target, field, rocket1, rocket2, rocket3, rocket4, rocket5, rocket6, bullet, explosion;
var oktoshoot = false, bulletlevel, speed = 10, missed = 0, fired = 0, hit = 0, accuracy = 0;
function init() {
target = eval('document.'+_all+'target'+_style);
field = eval('document.'+_all+'field'+_style);
rocket1 = eval('document.'+_all+'rocket1'+_style);
rocket2 = eval('document.'+_all+'rocket2'+_style);
rocket3 = eval('document.'+_all+'rocket3'+_style);
rocket4 = eval('document.'+_all+'rocket4'+_style);
rocket5 = eval('document.'+_all+'rocket5'+_style);
rocket6 = eval('document.'+_all+'rocket6'+_style);
bullet = eval('document.'+_all+'bullet'+_style);
explosion = eval('document.'+_all+'explosion'+_style);
resize();
if (isNS) {
target.moveTo(300,0);
}
else {
target.pixelLeft = 300;
target.pixelTop = 0;
}
target.visibility = _visible;
field.visibility = _visible;
alert('INSTRUCTIONS:\n\n- Try to hit the rockets before they reach the other side.\n- Fire the "gun" a little ahead of time to compensate for distances.\n- Simply target the rockets with the mouse and then click to fire the gun.\n- Press the spacebar to pause the game.\n- Pausing the game also shows your full stats.\n- Look in the status bar to see how many rockets you missed.\n\nPress "Ok" to start....');
loaded = true;
oktoshoot = true;
dispmisses();
animate();
}
function dispmisses() {
status = "Rockets missed: "+missed;
setTimeout('dispmisses()', 500);
}
function showstat() {
accuracy = (Math.round(hit/fired*100));
if (isNaN(accuracy)) {accuracy = 0};
alert('Game Paused.....\n\nPress OK to continue..\n\nShots fired: '+fired+'\nRockets destroyed: '+hit+'\nShots missed: '+(fired-hit)+'\nRockets missed: '+missed+'\nShot accuracy: '+accuracy+'%');
}
function testandmoveX(rocketN) {
if (isNS) {
rocketN.clip.left = -rocketN.left-speed;
rocketN.clip.right = 500-rocketN.left;
if (rocketN.left+speed&gt;500) {
rocketN.left = -60;
if (rocketN.top != -3000) { missed++; }
}
else {
rocketN.left+=speed;
}
if (rocketN.left == -60)rocketN.top = Math.floor(Math.random()*12)*20+30;
}
else {
rocketN.clip = "rect(0px, "+(500-speed-rocketN.pixelLeft)+"px, 15px, "+(-rocketN.pixelLeft-speed)+"px)"; 
if (rocketN.pixelLeft+speed &gt; 500) {
if (rocketN.pixelTop != -3000) {missed++}
rocketN.pixelLeft = -60;
}else {
rocketN.pixelLeft+=speed;
}
if (rocketN.pixelLeft == -60)rocketN.pixelTop = Math.floor(Math.random()*12)*20+30;
   }
}
function animate() {
for (i = 1; i &lt;= 6; i++) {
testandmoveX(eval('rocket'+i));
}
setTimeout('animate()',100);
}
function shootrocket(x,y) {
fired++;
bulletlevel = 4;
bullettime(x,y);
}

function bullettime(x,y) {
if (bulletlevel &gt; 0) {
if (isNS) {
bullet.clip.width = bulletlevel*4;
bullet.clip.height = bulletlevel*4;
bullet.moveTo(x-(bulletlevel*2),y-(bulletlevel*2));
if (bulletlevel == 1) {
for (r = 1;r &lt;= 6;r++) {
tr = eval('rocket'+r);
if ( (bullet.top &gt;= tr.top+2) && (bullet.top &lt;= tr.top+9) && (bullet.left &lt;= tr.left+57) && (bullet.left &gt;= tr.left) ) {
explosion.moveTo(tr.left,tr.top);
tr.top = -3000;
hit++;
setTimeout('explosion.top = -3000', 400);
         }
      }
   }
}
else {
bullet.width = bulletlevel*4;
bullet.height = bulletlevel*4;
bullet.pixelTop = y-(bulletlevel*2);
bullet.pixelLeft = x-(bulletlevel*2)
if (bulletlevel == 1) {
for (r = 1; r &lt;= 6; r++) {
tr = eval('rocket'+r);
if ( (bullet.pixelTop &gt;= tr.pixelTop+2) && (bullet.pixelTop &lt;= tr.pixelTop+9) && (bullet.pixelLeft &lt;= tr.pixelLeft+57) && (bullet.pixelLeft &gt;= tr.pixelLeft) ) {
explosion.pixelLeft = tr.pixelLeft;
explosion.pixelTop = tr.pixelTop;
tr.pixelTop = -3000;
hit++;
setTimeout('explosion.pixelTop = -3000', 400);
         }
      }
   }
}
bulletlevel--;
setTimeout('bullettime('+x+','+y+')',200);
}
else {
(isNS) ? bullet.top = -3000 : bullet.pixelLeft = -3000;
oktoshoot = true;
   }
}
function resize() {
if (isNS) {
xoffset = (window.innerWidth-300)/2;
document.outer.moveTo((window.innerWidth-500)/2 , yoffset);
}
else {
xoffset = (document.body.clientWidth-300)/2
document.all.outer.style.pixelTop = yoffset;
document.all.outer.style.pixelLeft = (document.body.clientWidth-500)/2;
   }
}
function movetarget(evnt) {
if (loaded) {
if (isNS) {
py = evnt.pageY-yoffset-59;
px = evnt.pageX-xoffset+59;
}
else {
py = event.clientY-yoffset-59;
px = event.clientX-xoffset+59;
}
if ((py &gt;= 0) && (py &lt;= 241)) { (isNS) ? target.top = py : target.pixelTop = py; };
if ((px &gt;= 0) && (px &lt;= 441)) { (isNS) ? target.left = px : target.pixelLeft = px };
return false;
   }
}

function fire(mouse) {
if (oktoshoot) {
oktoshoot = false;
(isNS) ? shootrocket(target.left+30,target.top+30) : shootrocket(target.pixelLeft+30,target.pixelTop+30) ; 
return false;
}
else {
   }
}
function reloadNS() {
setTimeout('reloadNS_1()', 500);
}
function reloadNS_1() {
window.location.reload();
}
(isNS) ? window.onresize = reloadNS : window.onresize = resize;

function getkeypress(keypress) {
keyp = (isNS) ? keypress.which : window.event.keyCode;
if (keyp == 32)showstat();
return false;
}
if (isNS) window.captureEvents(Event.KEYPRESS);
if (isNS) document.captureEvents(Event.KEYPRESS);
window.onkeypress = getkeypress;
document.onkeypress = getkeypress;

if (isNS) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = movetarget;

if (isNS) document.captureEvents(Event.MOUSEDOWN);
if (isNS) window.captureEvents(Event.MOUSEDOWN);
document.onmousedown = fire;
window.onmousedown = fire;

window.onload = init;
// End --&gt;
&lt;/script&gt;
&lt;/head&gt;
&lt;body bgcolor="#009090"&gt;

&lt;script language="JavaScript"&gt;

var basic = 'visibility="visible" width="60" top="-3000" height="15"';
var txt = '';
if (isNS) {
txt += '&lt;layer name="outer" visibility="visible" width="500"&gt;';
txt += '&lt;layer name="target" visibility="hidden" z-index="12"&gt;&lt;img src="target.gif"&gt;&lt;/layer&gt;';
txt += '&lt;layer name="field"  visibility="hidden" bgcolor="black" z-index="1" width="500" height="300"&gt;&lt;/layer&gt;';
txt += '&lt;layer name="explosion" '+basic+'z-index="11"&gt;&lt;img src="explosion.gif"&gt;&lt;/layer&gt;';
txt += '&lt;layer name="rocket1" '+basic+'left="-460" z-index="4"&gt;&lt;img src="rocket.gif"&gt;&lt;/layer&gt;';
txt += '&lt;layer name="rocket2" '+basic+'left="-380" z-index="5"&gt;&lt;img src="rocket.gif"&gt;&lt;/layer&gt;';
txt += '&lt;layer name="rocket3" '+basic+'left="-300" z-index="6"&gt;&lt;img src="rocket.gif"&gt;&lt;/layer&gt;';
txt += '&lt;layer name="rocket4" '+basic+'left="-220" z-index="7"&gt;&lt;img src="rocket.gif"&gt;&lt;/layer&gt;';
txt += '&lt;layer name="rocket5" '+basic+'left="-140" z-index="8"&gt;&lt;img src="rocket.gif"&gt;&lt;/layer&gt;';
txt += '&lt;layer name="rocket6" '+basic+'left="-60" z-index="9"&gt;&lt;img src="rocket.gif"&gt;&lt;/layer&gt;';
txt += '&lt;layer name="bullet" visibility="visible" width="10" top="-3000" height="10" bgcolor="white" z-index="10"&gt;&lt;/layer&gt;';
txt += '&lt;/layer&gt;';
}
else {
txt += '&lt;div id="outer" style="position:absolute; width:600px; height:300px"&gt;';
txt += '&lt;div id="field" style="position:absolute; top:0px; left:0px; visibility:hidden; width:500px; height:300px; z-index:2; background-color:black;"&gt;&lt;/div&gt;';
txt += '&lt;div id="target" style="position:absolute; visibility:hidden; z-index:12"&gt;&lt;img src="target.gif"&gt;&lt;/div&gt;';
txt += '&lt;div id="explosion" style="z-index:11;" class="basic"&gt;&lt;img src="explosion.gif"&gt;&lt;/div&gt;';
txt += '&lt;div id="rocket1" style="left:-460px; z-index:4" class="basic"&gt;&lt;img src="rocket.gif"&gt;&lt;/div&gt;';
txt += '&lt;div id="rocket2" style="left:-380px; z-index:5" class="basic"&gt;&lt;img src="rocket.gif"&gt;&lt;/div&gt;';
txt += '&lt;div id="rocket3" style="left:-300px; z-index:6" class="basic"&gt;&lt;img src="rocket.gif"&gt;&lt;/div&gt;';
txt += '&lt;div id="rocket4" style="left:-220px; z-index:7" class="basic"&gt;&lt;img src="rocket.gif"&gt;&lt;/div&gt;';
txt += '&lt;div id="rocket5" style="left:-140px; z-index:8" class="basic"&gt;&lt;img src="rocket.gif"&gt;&lt;/div&gt;';
txt += '&lt;div id="rocket6" style="left:-60px; z-index:9" class="basic"&gt;&lt;img src="rocket.gif"&gt;&lt;/div&gt;';
txt += '&lt;div id="bullet" style="z-index:10; background-color:white; width:10px; height:10px; font-size:1px;" class="basic"&gt;&lt;/div&gt;';
txt += '&lt;/div&gt;';
}
document.write(txt);
// End --&gt;
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;/HEAD&gt;

&lt;!-- STEP TWO: Paste the second code into your page to open the game  --&gt;

&lt;BODY&gt;

&lt;center&gt;
&lt;form name="open-rockets"&gt;
&lt;input type=button value="Play Rocket Blaster" onClick="window.open('rocket-blaster.html','rocketblaster','top=100,left=100,width=550,height=350');"&gt;
&lt;/form&gt;
&lt;/center&gt;

&lt;!-- STEP THREE: Save the game images and then upload them to your web server  --&gt;
&lt;!-- URL:  ../img/rocket-blaster/rocket-blaster.zip --&gt;


&lt;p&gt;&lt;center&gt;
&lt;font face="arial, helvetica" SIZE="-2"&gt;Free JavaScripts provided&lt;br&gt;
by &lt;a href="http://javascriptsource.com"&gt;JavaScript Source Code 3000&lt;/a&gt;&lt;/font&gt;
&lt;/center&gt;&lt;p&gt;

&lt;!-- Script Size:  9.26 KB --&gt;</textarea><br><font FACE="helvetica,arial,geneva"></font></td></tr>

</table>
</form>
</FONT>
</CENTER>


</center>
</body></html>
